package hclfns

import (
	"github.com/ihaiker/tfwrapper/internal/errors"
	"github.com/ihaiker/tfwrapper/internal/shells"
)

// Return the repository root as an absolute path
func getRepoRoot(opts *FunctionOptions) (string, error) {
	stdout, stderr, err := shells.New(
		"git", "rev-parse", "--show-toplevel").
		WorkingDir(opts.WorkingDir).
		RunWithOutput()
	if err != nil {
		err = errors.New(stderr)
	}
	return stdout, err
}
